//
//  ZYCHomeRootSectionHeaderView.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/29.
//

#import "ZYCHomeRootSectionHeaderView.h"
@interface ZYCHomeRootSectionHeaderView ()
@property (nonatomic, strong) UIButton *newsButton;
@property (nonatomic, strong) UIButton *bulletinButton;
@property (nonatomic, copy) NSString *noticeType;
@end
@implementation ZYCHomeRootSectionHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.noticeType = @"0";
        [self addSubview:self.newsButton];
        [self addSubview:self.bulletinButton];
        [self.newsButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(19.0f);
            make.centerY.equalTo(self);
        }];
        [self.bulletinButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.newsButton.mas_right).offset(12.5f);
            make.centerY.equalTo(self);
        }];
        [self clickBtnAction:self.newsButton];
    }
    return self;
}

- (UIButton *)newsButton {
    if (!_newsButton) {
        _newsButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_newsButton setTitle:@"新闻" forState:UIControlStateNormal];
        [_newsButton setTitleColor:HEX_RGB(kTitleMainColor) forState:UIControlStateNormal];
        _newsButton.tag = 1000;
        [_newsButton addTarget:self action:@selector(clickBtnAction:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _newsButton;
}

- (UIButton *)bulletinButton {
    if (!_bulletinButton) {
        _bulletinButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_bulletinButton setTitle:@"公告" forState:UIControlStateNormal];
        [_bulletinButton setTitleColor:HEX_RGB(kTitleLightGrayColor) forState:UIControlStateNormal];
        _bulletinButton.tag = 1001;
        [_bulletinButton addTarget:self action:@selector(clickBtnAction:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _bulletinButton;
}

- (void)clickBtnAction:(UIButton *)sender{
    
    sender.selected = !sender.selected;
    if (sender.tag == 1000) {//新闻
        self.noticeType = @"0";
        if (sender.selected) {
            sender.titleLabel.font = kSystemBoldFont(18.0f);
            [sender setTitleColor:HEX_RGB(kTitleMainColor) forState:UIControlStateSelected];
            self.bulletinButton.titleLabel.font = kSystemFont(13.0f);
            [self.bulletinButton setTitleColor:HEX_RGB(kTitleLightGrayColor) forState:UIControlStateSelected];
        }else{
            sender.titleLabel.font = kSystemFont(13.0f);
            [sender setTitleColor:HEX_RGB(kTitleLightGrayColor) forState:UIControlStateSelected];
            self.bulletinButton.titleLabel.font = kSystemBoldFont(18.0f);
            [self.bulletinButton setTitleColor:HEX_RGB(kTitleMainColor) forState:UIControlStateSelected];
        }
    }else{
        self.noticeType = @"1";
        if (sender.selected) {
            sender.titleLabel.font = kSystemBoldFont(18.0f);
            [sender setTitleColor:HEX_RGB(kTitleMainColor) forState:UIControlStateSelected];
            self.newsButton.titleLabel.font = kSystemFont(13.0f);
            [self.newsButton setTitleColor:HEX_RGB(kTitleLightGrayColor) forState:UIControlStateSelected];
        }else{
            sender.titleLabel.font = kSystemFont(13.0f);
            [sender setTitleColor:HEX_RGB(kTitleLightGrayColor) forState:UIControlStateSelected];
            self.newsButton.titleLabel.font = kSystemBoldFont(18.0f);
            [self.newsButton setTitleColor:HEX_RGB(kTitleMainColor) forState:UIControlStateSelected];
        }
    }
    
    if ([self.delegate respondsToSelector:@selector(homeRootSectionHeaderViewDidClick:)]) {
        [self.delegate homeRootSectionHeaderViewDidClick:self.noticeType];
    }
}

@end
